package com.example.springcloudwinter.controller;


import com.example.springcloudwinter.dto.ResultEntity;
import com.example.springcloudwinter.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;


@RefreshScope
@RestController
@RequestMapping("/user")
public class UserController {
    
    @Autowired
    private UserService userService;
    
    @GetMapping("/login")
    public ResultEntity<?> getUserByIdByPass(@RequestParam ("userId")String username, @RequestParam ("password") String password){
        return userService.login(username,password);
    }
    
    @PostMapping("/register")
    public ResultEntity<?> register(@RequestParam ("password") String password,
                                    @RequestParam("userId")String phoneNumber, @RequestParam("userSex")int sex,
                                    @RequestParam("userName")String nickname){
        return userService.register(nickname,password,phoneNumber,sex);
    }
    
    @GetMapping("/info")
    public ResultEntity<?> getUserById(@RequestParam ("userId")String username){
        return userService.getUserById(username);
    }
    
}
